package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.OrderStatisticsMapper;
import com.atguigu.spzx.manager.service.OrderInfoService;
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    OrderStatisticsMapper orderStatisticsMapper;


    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {

        List<OrderStatistics> orderStatisticsList =  orderStatisticsMapper.getOrderStatisticsData(orderStatisticsDto);

        List<String> dateList = orderStatisticsList.stream().map((orderStatistics)->new SimpleDateFormat("yyyy-MM-dd").format(orderStatistics.getOrderDate())).collect(Collectors.toList());
        List<BigDecimal> amountList = orderStatisticsList.stream().map(OrderStatistics::getTotalAmount).collect(Collectors.toList());

        OrderStatisticsVo vo = new OrderStatisticsVo();
        vo.setDateList(dateList);  //横坐标数据
        vo.setAmountList(amountList); //纵坐标数据
        return vo;
    }
}
